<%@ page language="java" contentType="text/html;charset=utf-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html lang="zh-cn" class="no-js">
<!--<![endif]-->
<head>
    <jsp:include page="../common/common.jsp"/>
    <link rel="stylesheet" type="text/css" href="${path}/assets/plugins/select2/select2.css"/>
    <link rel="stylesheet" type="text/css" href="${path}/assets/plugins/select2/select2-metronic.css"/>
</head>
<body class="page-header-fixed">
<!-- BEGIN HEADER -->
<jsp:include page="../common/header.jsp"/>
<div class="clearfix">
</div>
<!-- BEGIN CONTAINER -->
<div class="page-container">
    <div class="page-sidebar-wrapper">
        <jsp:include page="../common/menu.jsp"/>
    </div>
    <div class="page-content-wrapper">
        <div class="page-content">
            <!-- BEGIN PAGE CONTENT-->
            <div class="row">
                <div class="col-md-12">
                    <!-- BEGIN EXAMPLE TABLE PORTLET-->
                    <div class="portlet box purple">
                        <div class="portlet-title">
                            <div class="caption"><i class="fa fa-file-text-o"></i>友情链接信息列表</div>
                            <div class="tools">
                                <div class="actions">
                                    <button type="button" id="btnB" class="btn blue"><i class="fa fa-plus"></i> 新增</button>
                                    <button type="button" id="btnA" class="btn green"><i class="fa fa-long-arrow-up"></i> 恢复</button>
                                    <button type="button" id="btnC" class="btn dark"><i class="fa fa-plus"></i> 禁用</button>
                                	<button type="button" id="btnDel" class="btn red"><i class="fa fa-trash-o"></i> 删除</button>
                                </div>
                            </div>
                        </div>
                        <div class="portlet-body">
                        	<table class="table table-striped table-bordered table-hover" id="datalist"></table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<jsp:include page="../common/footer.jsp"/>
<script type="text/javascript" src="${path}/assets/plugins/select2/select2.min.js"></script>
<script>
    $(function () {
        $("#btnB").click(function (e) {// 新增
        	window.location.href = _path + "/operate/friendLinkAdd.jsp";
        });
        $("#btnA").click(function (e) {// 恢复
            oper(2);
        });
        $("#btnC").click(function (e) {// 禁用
            oper(4);
        });
        $("#btnDel").click(function (e) {// 删除
            oper(3);
        });
        query();
    });
    
    var brandTable;
    function query() {
        if (typeof brandTable !== 'undefined') {
        	brandTable.fnPageChange('first');
            return;
        }
        var i = 1;
        brandTable = $("#datalist").DataTable({
            "sAjaxSource": _path + "/friendLink/query",
            "sServerMethod": "POST",
            "sAjaxDataProp": "dataList",
            "fnCreatedRow": function () {
                i++;
            },
            "fnPreDrawCallback": function () {
                i = 1;
            },
            "aoColumns": [
				{ "sTitle": "选择", "sWidth": "2%","mData": function (data) {
				    return '<input type="checkbox" value="' + data.id + '"/>';
				}},
                { "sTitle": "序号", "sWidth": "2%","mData": function () {
                        return i;
                }},
                { "sTitle": "网站名称", "mData": "name", "sWidth": "10%" },
                { "sTitle": "链接地址", "mData": "url", "sWidth": "10%" },
                { "sTitle": "LOGO图标地址", "sWidth": "10%" ,"mData": function (data) {
		            return "<img style='height:35px;width:60px' src='" + data.logourl + "'/>";
		        }},
                { "sTitle": "结束时间", "mData": "efftime", "sWidth": "10%" },
                { "sTitle": "备注", "mData": "remark", "sWidth": "10%" },
                { "sTitle": "审核状态", "mData": "status", "sWidth": "10%",
                    "mRender": function (data) {
                        var status = '';
                        switch (data) {
                            case 0:
                                status = '正常';
                                break;
                            case 1:
                                status = '禁用';
                                break;
                        }
                        return status;
                    }
                },
                { "sTitle": "操作", "sWidth": "10%","mData": function (data) {
                	return '<div style="width: 80px;">'
                		 + '<a href="' + _path + '/friendLink/edit?id=' + data.id + '" class="btn default btn-xs purple">'
                		 + '<i class="fa fa-edit"></i> 编辑'
				         + '</a>'
				         + '</div>';
                }}
            ]
        });
    }
    
    function oper(type) {
       var inputs = $("input:checked");
       if (inputs.length > 0) {
           var id = new Array();
           for (var i = 0, len = inputs.length; i < len; i++) {
           		id.push(inputs[i].value);
           }
           App.ajax(_path + "/friendLink/updBatch", "ids=" + id.join() + "&type=" + type, function (data) {
               switch (data.statusCode) {
                   case 200 :
                       App.bubble(200, "操作成功！");
                       break;
                   case 500 :
                       App.bubble(500, data.info);
                       break;
                   default :
                   	   App.bubble(100, "操作失败！");
                       break;
               }
               window.location.href = _path + "/friendLink/list/0";
           });
       } else {
           App.bubble(100, "请选择要修改的记录！");
       }
    }
</script>
</body>
<!-- END BODY -->
</html>